package cn.inurl.logic;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import cn.inurl.bean.NLogBean;
import cn.inurl.util.RegexUtil;

public class AnalysisLogic {
	
	private static AnalysisLogic al;
	private AnalysisLogic(){}
	public static AnalysisLogic getInstance(){
		if(al == null)
			al = new AnalysisLogic();
		return al;
	}
	
	public List<NLogBean> getNginxLogBeans(String fileName){
		File file = new File(fileName);
        BufferedReader reader = null;
        List<NLogBean> beans = new ArrayList<NLogBean>();
        try {
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            NLogBean bean = null;
            while ((tempString = reader.readLine()) != null) {
            	bean = RegexUtil.getNLogBean(tempString);
            	beans.add(bean);
//            	System.out.println(bean);
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }
		return beans;
	}
	
	public static void main(String[] args) {
		getInstance().getNginxLogBeans("C:\\Documents and Settings\\dongyshd\\My Documents\\Downloads\\www.303i.com.log");
	}
}
